﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LotteryVote.Entity;
using LotteryVote.Data;
using LotteryVote.Utility;

namespace LotteryVote.Logic
{
    public static class SystemErrorLog
    {
        private static SystemErrorDataAccess DaError = new SystemErrorDataAccess();
        public static void LogError(Exception innerException, ErrorLevel level, string pageUrl)
        {
            SystemError error = new SystemError
            {
                ErrorLevel = level,
                ErrorMessage = innerException.Message,
                StackTrack = innerException.StackTrace,
                PageUrl = pageUrl
            };
            try
            {
                DaError.Insert(error);
            }
            catch (Exception ex)
            {
                Func<string> getDividingLines = () => { string line = string.Empty; for (int i = 0; i < 20; i++)line += "-"; return line; };
                LogConsole.Error(getDividingLines() + "插入日志失败" + getDividingLines());
                LogConsole.Error("插入SystemError失败!", ex);
                LogConsole.Error(getDividingLines() + getDividingLines());
            }
        }
    }
}
